//
//  ViewController.m
//  Button防止多次点击
//
//  Created by keisun on 2018/3/26.
//  Copyright © 2018年 keisun. All rights reserved.
//

#import "ViewController.h"
#import "UIControl+Extension.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 100, 50)];
    [btn setTitle:@"可防点击" forState:UIControlStateNormal];
    btn.backgroundColor = [UIColor greenColor];
    btn.eventInternal = 0.5;
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchDown];
    [self.view addSubview:btn];
    
    
    
    //与以上作为对比，且旨在说明无论有多少按钮，UIControl的load只打印一次基类。initialize先只打印一次基类，再打印一次子类
    UIButton *btn2 = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMaxX(btn.frame)+30, 100, 50, 50)];
    [btn2 setTitle:@"点击" forState:UIControlStateNormal];
    btn2.backgroundColor = [UIColor redColor];
    [btn2 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchDown];
    [self.view addSubview:btn2];
    
    UIButton *btn3 = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMaxX(btn2.frame)+30, 100, 50, 50)];
    [btn3 setTitle:@"点击" forState:UIControlStateNormal];
    btn3.backgroundColor = [UIColor blueColor];
    [btn3 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchDown];
    [self.view addSubview:btn3];
}

-(void)btnClick:(UIButton *)btn{
    NSLog(@"点击一下");
}

@end
